import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Rectangle {
    Layout.fillWidth: true
    Layout.fillHeight: true

    // 解决了同步滚动的问题
    Flickable {
        anchors.fill: parent
        contentWidth: parent.width
        contentHeight: Math.max(markdownPreview.implicitHeight,
                                markdownInput.implicitHeight,
                                parent.height)
        clip: true
        ScrollBar.vertical: ScrollBar {}

        SplitView {
            anchors.fill: parent

            // Markdown输入区域
            TextArea {
                id: markdownInput
                SplitView.preferredWidth: parent.width / 2
                placeholderText: "输入Markdown文本..."
                font.family: "Courier New"
                wrapMode: TextArea.Wrap
            }

            // Markdown预览区域
            Text {
                id: markdownPreview
                width: parent.width
                wrapMode: Text.Wrap
                textFormat: Text.MarkdownText
                text: markdownInput.text
                padding: 10
                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }
}
